package mytest;

/**
 * Created by thinkpad on 2015/1/1.
 */
//: Alias1.java
// Aliasing two handles to one object
public class Alias1 {
    int i;
    private AliasBase aliasBase;
    Alias1(int ii) { i = ii; }
//    Alias1(AliasBase aliasBase) {
//        this.aliasBase = aliasBase;
//        this.i = aliasBase.getI();
//     }

    Alias1(AliasBase aliasBase) {
        this.aliasBase = new AliasBase(aliasBase.getI());
        this.i = aliasBase.getI();
    }

    AliasBase addExI(AliasBase aliasBase) {
        AliasBase temp = new AliasBase(aliasBase.getI());
        aliasBase = temp; //形式参数值传递，没有意义，不影响实际参数
        this.aliasBase = temp;
        return temp;
    }

    Alias1(AliasBaseBase aliasBaseBase) {
        this.aliasBase =  new AliasBase(aliasBaseBase);
        this.i = aliasBaseBase.getI();
    }


    public static void main(String[] args) {
//        Alias1 x = new Alias1(7);
//        Alias1 y = x; //Assign the handle
        AliasBase aliasBase = new AliasBase(9);
        Alias1 x = new Alias1(aliasBase);

        System.out.println("x.aliasBase.i: " + x.aliasBase.getI());
        System.out.println("aliasBase.i: " + aliasBase.getI());
        System.out.println("Incrementing x");
//        x.i++;
        aliasBase.addI();
        System.out.println("x.aliasBase.i: " + x.aliasBase.getI());
        System.out.println("aliasBase.i: " + aliasBase.getI());
        System.out.println("x.aliasBase.toString(): " + x.aliasBase.toString());
        System.out.println("aliasBase.toString(): " + aliasBase.toString());

        AliasBaseBase aliasBaseBase = new AliasBaseBase(20);
        Alias1 y = new Alias1(aliasBaseBase);
        System.out.println("y.aliasBase.getAliasBase().i: " + y.aliasBase.getAliasBase().getI());
        System.out.println("y.aliasBase.getAliasBaseBase().i: " +y.aliasBase.getAliasBaseBase().getI());
        System.out.println("aliasBaseBase.i: " + aliasBaseBase.getI());
        System.out.println("Incrementing y");
        aliasBaseBase.addI();

        System.out.println("y.aliasBase.getAliasBase().i: " + y.aliasBase.getAliasBase().getI());
        System.out.println("y.aliasBase.getAliasBaseBase().i: " +y.aliasBase.getAliasBaseBase().getI());
        System.out.println("aliasBaseBase.i: " + aliasBaseBase.getI());
        System.out.println("y.aliasBase.toString(): " + y.aliasBase.toString());
        System.out.println("y.aliasBase.getAliasBaseBase().toString(): " + y.aliasBase.getAliasBaseBase().toString());
        System.out.println("aliasBaseBase.toString(): " + aliasBaseBase.toString());


        Alias1 z = new Alias1(aliasBase);
        System.out.println("before addExI z.aliasBase.toString(): " + z.aliasBase.toString());
        System.out.println("before addExI aliasBase.toString(): " + aliasBase.toString());
        AliasBase temp = z.addExI(aliasBase);
        System.out.println("z.aliasBase.toString(): " + z.aliasBase.toString());
        System.out.println("aliasBase.toString(): " + aliasBase.toString());
        System.out.println("temp.toString(): " + temp.toString());

        String t1 = "1234";
        byte[] t2 = t1.getBytes();
        System.out.println("t2.length: " + t2.length);
        int tx = -1,ty = 0;
        ty = tx++ + ++tx;
        System.out.println("ty:"+ty);
        float a = 9.0f;
        int i = 0;
        i = i++;
        System.out.println("i:"+ i);

        char p1 = 't';
        int  h1 = 9;
        System.out.println(false?h1:p1);
        System.out.println(false?9:p1);
        System.out.println(h1>>33);
        final Alias1 k = new Alias1(1);
        k.i = 2;

    }
;} ///:~